package com.hualan.sfzyproject.controller;


import com.hualan.sfzyproject.domain.PrivateMessage;
import com.hualan.sfzyproject.service.PrivateMessageService;
import com.hualan.sfzyproject.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("privateMessage")
public class PrivateMessageController {
    @Autowired
    private PrivateMessageService privateMessageService;

    @RequestMapping("selectByConsultantId")
    public R selectByConsultantId(Integer consultantId){
        List<PrivateMessage> privateMessageList = privateMessageService.selectByConsultantId(consultantId);
        if (privateMessageList == null){
            return R.fail("无数据");
        }else{
            return R.ok(privateMessageList);
        }
    }

    @PutMapping
    public R update(@RequestBody PrivateMessage privateMessage){
        int i = privateMessageService.update(privateMessage);
        if (i == 1){
            return R.ok("修改成功");
        }else{
            return R.fail("修改失败");
        }
    }

    @DeleteMapping("/{sixinid}")
    public R delete(@PathVariable("sixinid") Integer sixinId){
        int i = privateMessageService.delete(sixinId);
        if (i == 1){
            return R.ok("删除成功");
        }else{
            return R.fail("删除失败");
        }
    }

    @GetMapping
    public R selectByUserId(Integer userId){
        List<PrivateMessage> privateMessageList = privateMessageService.selectByUserId(userId);
        if (privateMessageList == null){
            return R.fail("无数据");
        }else{
            return R.ok(privateMessageList);
        }
    }

    @PostMapping
    public R insert(@RequestBody PrivateMessage privateMessage){
        int i = privateMessageService.insert(privateMessage);
        if (i == 1){
            return R.ok("添加成功");
        }else{
            return R.fail("添加失败");
        }
    }



}
